package vrp;

import java.io.IOException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;

import vrp.PMF;
import vrp.Partner;


public class PartnerAddServlet extends HttpServlet {

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

        PersistenceManager pm = PMF.get().getPersistenceManager();

        String name = req.getParameter("name");
        String address = req.getParameter("address");
        String postalCode = req.getParameter("postalCode");
        String contactNo = req.getParameter("contactNo");
        int type = Integer.parseInt(req.getParameter("type"));
        String responseRedirect = "";
        switch (type) {
        case 0:
        	responseRedirect += "/clients.jsp";
        	break;
        case 1:
        	responseRedirect += "/carriers.jsp";
        	break;
        case 2:
        	responseRedirect += "/whproviders.jsp";
        	break;
        }

        try {
        	Partner partner = new Partner(name, address, postalCode, contactNo, type);
            pm.makePersistent(partner);
        } finally {
            pm.close();
        }
        resp.sendRedirect(responseRedirect);
    }
}
